package com.thoughtworks.conference.dao.impl;

import com.thoughtworks.conference.constants.CommonConstants;
import com.thoughtworks.conference.dao.ConferenceTrackDao;
import com.thoughtworks.conference.model.SessionTalkInfo;
import com.thoughtworks.conference.model.TrackInfo;
import com.thoughtworks.conference.model.TrackSession;
import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * <p>Title:会议跟踪管理的数据打印接口实现类 </p>
 * <p>Description:打印会议跟踪安排信息</p>
 *
 * @author <a href="mailTo:bingxuewulei@outlook.com">wanglei</a>
 * @version 1.0
 * @history: Created by wanglei on  2019/4/25
 */
public class ConferenceTrackDaoImpl implements ConferenceTrackDao {
    @Override
    public void printConferenceTrackInfo(List<TrackInfo> trackInfoList) {
        // 判空卫语句
        if (null==trackInfoList||trackInfoList.isEmpty()){
            return;
        }
        // 循环打印会议信息
        trackInfoList.forEach(trackInfo->{
            // 打印追踪编号
            System.out.println(trackInfo.getTrackNum());
            // 打印早上的会议信息
            printSession(trackInfo.getMorningTrackSession());
            // 打印午饭安排
            printSession(trackInfo.getLunchSession());
            // 打印下午会议安排时间
            printSession(trackInfo.getAfterNoonTrackSession());
            // 打印网络活动信息
            printSession(trackInfo.getNetWorkSession());

        });
    }

    /**
     * 打印单个会议安排
     * @param trackSession
     */
    private void printSession(TrackSession trackSession){
        printSessionTalks(trackSession.getMorningSessionTalkInfo());
        printSessionTalk(trackSession.getLunchTalkInfo());
        printSessionTalks(trackSession.getAfterNoonSessionTalkInfo());
        printSessionTalk(trackSession.getNetWorkTalkInfo());
    }

    /**
     * 打印多个会议安排
     * @param sessionTalkInfos 会议安排列表
     */
    private void printSessionTalks(List<SessionTalkInfo> sessionTalkInfos){
        if(null==sessionTalkInfos ||sessionTalkInfos.isEmpty()){
            return;
        }
        // 循环输出会议安排信息
        sessionTalkInfos.forEach(sessionTalkInfo -> {
            printSessionTalk(sessionTalkInfo);
        });
    }

    /**
     * 打印会议安排信息
     * @param sessionTalkInfo 会议安排信息
     */
    private void printSessionTalk(SessionTalkInfo sessionTalkInfo){
        if(null==sessionTalkInfo){
            return;
        }
        // 输出时间格式化
        SimpleDateFormat sdf = CommonConstants.DATE_FORMAT;
        Calendar sessionTalkInfoStartTime = sessionTalkInfo.getSessionTalkInfoStartTime();
        String sessionTalkInfoTitle = sessionTalkInfo.getSessionTalkInfoTitle();
        if(null== sessionTalkInfoStartTime){
            return;
        }
        // 组装输出会议安排信息
        if(StringUtils.isEmpty(sessionTalkInfo.getGetSessionTalkInfoTMinutes())){
            System.out.println(sdf.format(sessionTalkInfoStartTime.getTime()) + " " + sessionTalkInfoTitle);
        }else{
            System.out.println(sdf.format(sessionTalkInfoStartTime.getTime())+ " " + sessionTalkInfoTitle
                    + " " + sessionTalkInfo.getGetSessionTalkInfoTMinutes());
        }

    }
}
